﻿using System;
namespace Producers.Arireg.Xtee.Riik.Ee.Producer.Arireg {
    
    
    [global::Xtee.Core.Attributes.XmlTypeAttribute(Name="mtatrahvid_trahv", Namespace="http://producers.arireg.xtee.riik.ee/producer/arireg", Target=typeof(MtatrahvidTrahv))]
    public class MtatrahvidTrahvSerializer : global::Xtee.Core.Types.AbstractXteeSerializable {
        
        protected IMtatrahvidTrahv clazz;
        
        public MtatrahvidTrahvSerializer(IMtatrahvidTrahv clazz) {
            this.clazz = clazz;
        }
        
        public override void WriteXml(global::Xtee.Core.IXteeXmlWriter Writer) {
            base.WriteXml(Writer);
            Writer.WriteStartElement("trahvi_id");
            Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "integer");
            Writer.WriteString(new global::Xtee.Core.Schema.XsdInteger(((decimal)(clazz.TrahviId))).ToString());
            Writer.WriteEndElement();
            Writer.WriteStartElement("ark");
            Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "integer");
            Writer.WriteString(new global::Xtee.Core.Schema.XsdInteger(((decimal)(clazz.Ark))).ToString());
            Writer.WriteEndElement();
            Writer.WriteStartElement("otsuse_liik");
            if (clazz.OtsuseLiik!=null) {
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.OtsuseLiik))).ToString());
            }
            else {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : OtsuseLiik");
            }
            Writer.WriteEndElement();
            Writer.WriteStartElement("otsuse_kpv");
            Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "date");
            Writer.WriteString(new global::Xtee.Core.Schema.XsdDate(((System.DateTime)(clazz.OtsuseKpv))).ToString());
            Writer.WriteEndElement();
            Writer.WriteStartElement("olek");
            if (clazz.Olek!=null) {
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.Olek))).ToString());
            }
            else {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : Olek");
            }
            Writer.WriteEndElement();
            Writer.WriteStartElement("oleku_muutm_kpv");
            Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "date");
            Writer.WriteString(new global::Xtee.Core.Schema.XsdDate(((System.DateTime)(clazz.OlekuMuutmKpv))).ToString());
            Writer.WriteEndElement();
            Writer.WriteStartElement("eesnimi");
            if (clazz.Eesnimi!=null) {
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.Eesnimi))).ToString());
            }
            else {
                Writer.WriteAttributeString("xsi", "nil", null, "1");
            }
            Writer.WriteEndElement();
            Writer.WriteStartElement("liignimi");
            if (clazz.Liignimi!=null) {
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.Liignimi))).ToString());
            }
            else {
                Writer.WriteAttributeString("xsi", "nil", null, "1");
            }
            Writer.WriteEndElement();
            Writer.WriteStartElement("isikukood");
            if (clazz.Isikukood!=null) {
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.Isikukood))).ToString());
            }
            else {
                Writer.WriteAttributeString("xsi", "nil", null, "1");
            }
            Writer.WriteEndElement();
            Writer.WriteStartElement("synnipaev");
            if (clazz.Synnipaev!=null) {
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "date");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdDate(((System.DateTime)(clazz.Synnipaev))).ToString());
            }
            else {
                Writer.WriteAttributeString("xsi", "nil", null, "1");
            }
            Writer.WriteEndElement();
            Writer.WriteStartElement("otsused_id");
            Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "integer");
            Writer.WriteString(new global::Xtee.Core.Schema.XsdInteger(((decimal)(clazz.OtsusedId))).ToString());
            Writer.WriteEndElement();
        }
        
        public override void ReadXml(global::Xtee.Core.IXteeXmlReader Reader) {
            base.ReadXml(Reader);
            if (Reader.LocalName=="trahvi_id") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>mtatrahvid_trahv>trahvi_id");
                }
                clazz.TrahviId = new global::Xtee.Core.Schema.XsdInteger(Reader.ReadElementString("trahvi_id")).Value;
            }
            else {
                throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>mtatrahvid_trahv>trahvi_id", Reader.LocalName);
            }
            if (Reader.LocalName=="ark") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>mtatrahvid_trahv>ark");
                }
                clazz.Ark = new global::Xtee.Core.Schema.XsdInteger(Reader.ReadElementString("ark")).Value;
            }
            else {
                throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>mtatrahvid_trahv>ark", Reader.LocalName);
            }
            if (Reader.LocalName=="otsuse_liik") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>mtatrahvid_trahv>otsuse_liik");
                }
                clazz.OtsuseLiik = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("otsuse_liik")).Value;
            }
            else {
                throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>mtatrahvid_trahv>otsuse_liik", Reader.LocalName);
            }
            if (Reader.LocalName=="otsuse_kpv") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>mtatrahvid_trahv>otsuse_kpv");
                }
                clazz.OtsuseKpv = new global::Xtee.Core.Schema.XsdDate(Reader.ReadElementString("otsuse_kpv")).Value;
            }
            else {
                throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>mtatrahvid_trahv>otsuse_kpv", Reader.LocalName);
            }
            if (Reader.LocalName=="olek") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>mtatrahvid_trahv>olek");
                }
                clazz.Olek = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("olek")).Value;
            }
            else {
                throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>mtatrahvid_trahv>olek", Reader.LocalName);
            }
            if (Reader.LocalName=="oleku_muutm_kpv") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>mtatrahvid_trahv>oleku_muutm_kpv");
                }
                clazz.OlekuMuutmKpv = new global::Xtee.Core.Schema.XsdDate(Reader.ReadElementString("oleku_muutm_kpv")).Value;
            }
            else {
                throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>mtatrahvid_trahv>oleku_muutm_kpv", Reader.LocalName);
            }
            if (Reader.LocalName=="eesnimi") {
                if ((Reader.IsElementNil() == false)) {
                    clazz.Eesnimi = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("eesnimi")).Value;
                }
                else {
                    Reader.Skip();
                }
            }
            else {
                throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>mtatrahvid_trahv>eesnimi", Reader.LocalName);
            }
            if (Reader.LocalName=="liignimi") {
                if ((Reader.IsElementNil() == false)) {
                    clazz.Liignimi = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("liignimi")).Value;
                }
                else {
                    Reader.Skip();
                }
            }
            else {
                throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>mtatrahvid_trahv>liignimi", Reader.LocalName);
            }
            if (Reader.LocalName=="isikukood") {
                if ((Reader.IsElementNil() == false)) {
                    clazz.Isikukood = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("isikukood")).Value;
                }
                else {
                    Reader.Skip();
                }
            }
            else {
                throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>mtatrahvid_trahv>isikukood", Reader.LocalName);
            }
            if (Reader.LocalName=="synnipaev") {
                if ((Reader.IsElementNil() == false)) {
                    clazz.Synnipaev = new global::Xtee.Core.Schema.XsdDate(Reader.ReadElementString("synnipaev")).Value;
                }
                else {
                    Reader.Skip();
                }
            }
            else {
                throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>mtatrahvid_trahv>synnipaev", Reader.LocalName);
            }
            if (Reader.LocalName=="otsused_id") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>mtatrahvid_trahv>otsused_id");
                }
                clazz.OtsusedId = new global::Xtee.Core.Schema.XsdInteger(Reader.ReadElementString("otsused_id")).Value;
            }
            else {
                throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>mtatrahvid_trahv>otsused_id", Reader.LocalName);
            }
        }
    }
}
